package com.yidu.DailyFinalTreatment.service.impl;

import com.yidu.BusinessData.mapper.BondMapper;
import com.yidu.CashAdministration.entity.MoneyAllocateEntity;
import com.yidu.DailyFinalTreatment.entity.NetWorth;
import com.yidu.DailyFinalTreatment.mapper.NetWorthMapper;
import com.yidu.DailyFinalTreatment.service.NetWorthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NetWorthServiceImpl implements NetWorthService {
    @Autowired
    private NetWorthMapper netWorthMapper;

    @Override
    public List<NetWorth> selectNeyWorth(String netWorthDate) {
        return netWorthMapper.selectNeyWorth(netWorthDate);
    }

    @Override
    public void deleteNetWorth(String netWorthDate, String fundId) {
        netWorthMapper.deleteNetWorth(netWorthDate,fundId);
    }

    @Override
    public int insertNetWorth(NetWorth netWorth) {
        Map map = new HashMap();
        map.put("string",string(netWorth));
        map.put("netWorthDate",netWorth.getNetWorthDate());
        map.put("fundId",netWorth.getFundId());
        map.put("projectId",netWorth.getProjectId());
        map.put("projectName",netWorth.getProjectName());
        map.put("stringTwo",stringTwo(netWorth));
        int i = netWorthMapper.insertNetWorth(map);
        return i;
    }

    public String string(NetWorth netWorth) {
        StringBuffer sqlWhere = new StringBuffer("") ;
        if (netWorth.getProjectCode()!=null && !netWorth.getProjectCode().equals("")){
            sqlWhere.append("projectCode,");
        }if(netWorth.getShareNum()!=0){
            sqlWhere.append("shareNum,");
        }if(netWorth.getStopPrice()!=0.0){
            sqlWhere.append("stopPrice,");
        }if(netWorth.getCapital()!=0.0){
            sqlWhere.append("capital,");
        }if(netWorth.getMarketValue()!=0.0){
            sqlWhere.append("marketValue,");
        }if(netWorth.getEstimate()!=0.0){
            sqlWhere.append("estimate,");
        }
        sqlWhere.append("projectFatherId");
        return sqlWhere.toString();
    }

    public String stringTwo(NetWorth netWorth) {
        StringBuffer sqlWhere = new StringBuffer("") ;
        if (netWorth.getProjectCode()!=null && !netWorth.getProjectCode().equals("")){
            sqlWhere.append(netWorth.getProjectCode()+",");
        }if(netWorth.getShareNum()!=0){
            sqlWhere.append(netWorth.getShareNum()+",");
        }if(netWorth.getStopPrice()!=0.0){
            sqlWhere.append(netWorth.getStopPrice()+",");
        }if(netWorth.getCapital()!=0.0){
            sqlWhere.append(netWorth.getCapital()+",");
        }if(netWorth.getMarketValue()!=0.0){
            sqlWhere.append(netWorth.getMarketValue()+",");
        }if(netWorth.getEstimate()!=0.0){
            sqlWhere.append(netWorth.getEstimate()+",");
        }
        sqlWhere.append(netWorth.getProjectFatherId()+"");
        return sqlWhere.toString();
    }
}
